package svc

import (
	"github.com/zeromicro/go-zero/rest"
	"github.com/zeromicro/go-zero/zrpc"
	"three-sxp/api/internal/config"
	"three-sxp/api/internal/middleware"
	"three-sxp/cartrpc/cartrpcclient"
	"three-sxp/goodsrpc/goodsrpcclient"
	"three-sxp/orderrpc/orderrpcclient"
	"three-sxp/userrpc/userrpcclient"
)

type ServiceContext struct {
	Config    config.Config
	UserRpc   userrpcclient.Userrpc
	GoodsRpc  goodsrpcclient.Goodsrpc
	CartRpc   cartrpcclient.Cartrpc
	OrderRpc  orderrpcclient.Orderrpc
	AuthToken rest.Middleware
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:    c,
		UserRpc:   userrpcclient.NewUserrpc(zrpc.MustNewClient(c.UserRpc)),
		GoodsRpc:  goodsrpcclient.NewGoodsrpc(zrpc.MustNewClient(c.GoodsRpc)),
		CartRpc:   cartrpcclient.NewCartrpc(zrpc.MustNewClient(c.CartRpc)),
		OrderRpc:  orderrpcclient.NewOrderrpc(zrpc.MustNewClient(c.OrderRpc)),
		AuthToken: middleware.NewAuthTokenMiddleware().Handle,
	}
}
